import '../model/dict_model.dart';
import '../model/paging_model.dart';
import '../utils/request.dart';

/// 字典API
class DictApi {
  DictApi._();

  static final _signleton = DictApi._();

  factory DictApi() => _signleton;

  /// 字典数据
  Future<List<DictDataRes>> dict(final DictDataReq req) => request
          .getHandler(path: '/dict/code/${req.code}', params: req.toMap())
          .then(
        (res) {
          final items = res.toList;
          if (items.isNotEmpty) {
            return parseToRows(items, (row) => DictDataRes.fromMap(row));
          }
          return <DictDataRes>[];
        },
      );
}

/// 字典接口单例
final dictApi = DictApi();
